using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class PInventoryLogMap : EntityTypeConfiguration<PInventoryLog>
    {
        public PInventoryLogMap()
        {
            // Primary Key
            this.HasKey(t => new { t.Item, t.Location, t.Date, t.ExpiryDate });

            // Properties
            this.Property(t => t.Item)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.Location)
                .IsRequired()
                .HasMaxLength(3);

            this.Property(t => t.desc)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("PInventoryLog");
            this.Property(t => t.Item).HasColumnName("Item");
            this.Property(t => t.Qty).HasColumnName("Qty");
            this.Property(t => t.Location).HasColumnName("Location");
            this.Property(t => t.Date).HasColumnName("Date");
            this.Property(t => t.OnHandTilldate).HasColumnName("OnHandTilldate");
            this.Property(t => t.Transqty).HasColumnName("Transqty");
            this.Property(t => t.oldPhy_date).HasColumnName("oldPhy_date");
            this.Property(t => t.price).HasColumnName("price");
            this.Property(t => t.desc).HasColumnName("desc");
            this.Property(t => t.Onhand).HasColumnName("Onhand");
            this.Property(t => t.ExpiryDate).HasColumnName("ExpiryDate");

            // Relationships
            this.HasRequired(t => t.Item1)
                .WithMany(t => t.PInventoryLogs)
                .HasForeignKey(d => d.Item);

        }
    }
}
